/*
 *
 * Copyright(c) 2018-2019 chj <1019487871@qq.com>
 * QQ: 1019487871
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
#include "los.h"

struct los_copy_record_t{
    uint32_t load_start_address;
    uint32_t run_start_address;
    uint32_t size;
    uint32_t type;    //0:zero init;    1:copy
};

struct los_copy_table_t{
    uint32_t record_size;
    uint32_t record_cnt;
    struct los_copy_record_t record[1];
};

extern struct los_copy_table_t los_copy_table;

void
los_loader(void)
{
   volatile  uint32_t *src = NULL,*des = NULL;
   volatile  uint32_t i = 0, j = 0;

    for(i=0; i<los_copy_table.record_cnt; i++) {
        src = (uint32_t*) los_copy_table.record[i].load_start_address;
        des = (uint32_t*) los_copy_table.record[i].run_start_address;
        if(los_copy_table.record[i].type == 1) {    //copy
            if(src != des) {
                for(j=0; j<los_copy_table.record[i].size; src++,des++) {
                    *des=*src;
                    j+=4;
                }
            }
        } else if(los_copy_table.record[i].type == 0) {    //zero init
            for(j=0; j<los_copy_table.record[i].size; des++) {
                *des=0;
                j+=4;
            }
        }
    }
}


